package com.api.shopapi.mapper;

import com.api.shopapi.entity.EElderlyRelatives;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface EElderlyRelativesMapper {

    @Insert("insert into e_elderly_relatives (ElderlyRelativesCode,UserCode,ElderlyCode,ElderlyName,Name,Phone,Relation," +
            "IsReceive,IsLive,Address,CreateTime,StaffCode,GovernmentCode) values " +
            "(#{elderlyRelatives.ElderlyRelativesCode},#{elderlyRelatives.UserCode},#{elderlyRelatives.ElderlyCode},#{elderlyRelatives.ElderlyName}," +
            "#{elderlyRelatives.Name},#{elderlyRelatives.Phone},#{elderlyRelatives.Relation},#{elderlyRelatives.IsReceive}," +
            "#{elderlyRelatives.IsLive},#{elderlyRelatives.Address},#{elderlyRelatives.CreateTime},#{elderlyRelatives.StaffCode},#{elderlyRelatives.GovernmentCode})")
    int insert(@Param("elderlyRelatives") EElderlyRelatives elderlyRelatives);

    @Update("update e_elderly_relatives set Name=#{elderlyRelatives.Name},Phone=#{elderlyRelatives.Phone}," +
            "Relation=#{elderlyRelatives.Relation},IsReceive=#{elderlyRelatives.IsReceive},IsLive=#{elderlyRelatives.IsLive}," +
            "Address=#{elderlyRelatives.Address} where ElderlyRelativesCode=#{elderlyRelatives.ElderlyRelativesCode}")
    int update(@Param("elderlyRelatives") EElderlyRelatives elderlyRelatives);

    @Delete("delete from e_elderly_relatives where ElderlyRelativesCode=#{elderlyRelativesCode}")
    int delete(@Param("elderlyRelativesCode") String elderlyRelativesCode);

    @Select("select * from e_elderly_relatives where ElderlyRelativesCode=#{elderlyRelativesCode} limit 1")
    EElderlyRelatives getByElderlyRelativesCode(@Param("elderlyRelativesCode") String elderlyRelativesCode);

    @Select("select * from e_elderly_relatives where ElderlyCode=#{elderlyCode} order by CreateTime desc")
    List<EElderlyRelatives> getPageList(@Param("elderlyCode") String elderlyCode);

}
